.PHONY: flash clean

TOOLCHAIN = arm-none-eabi
FLAGS = -g -mcpu=cortex-m3
CC = $(TOOLCHAIN)-gcc
CFLAGS = $(FLAGS) -mthumb -Ilib
AS = $(TOOLCHAIN)-as
ASFLAGS = $(FLAGS)

OBJECTS = lib/startup_stm32f10x_md.o lib/system_stm32f10x.o lib/misc.o main.o
OBJECTS += lib/stm32f10x_rcc.o
OBJECTS += lib/stm32f10x_tim.o
OBJECTS += lib/stm32f10x_gpio.o
OBJECTS += lib/stm32f10x_usart.o
OBJECTS += lib/stm32f10x_spi.o
OBJECTS += timer.o
OBJECTS += keyboard.o
OBJECTS += uart.o
OBJECTS += lcd.o

app.bin: app.elf
	$(TOOLCHAIN)-objcopy -O binary app.elf app.bin

app.elf: link.ld $(OBJECTS)
	$(TOOLCHAIN)-ld -T link.ld $(OBJECTS) -o app.elf

flash:
	openocd -f interface/stlink.cfg -f target/stm32f1x_cn.cfg -c "program app.bin reset exit 0x08000000"

clean:
	del /S *.o *.elf *.bin
